// 导入axios
import axios from "axios";
// 导入API地址
import { api } from './api_address';
// 导入服务器地址
import { HOST_URL } from './host';

// 创建实例
let token = localStorage.getItem('auto_token')
const http = axios.create({
    headers: { token }
});

// 配置请求拦截器
http.interceptors.request.use(config => {
    // 请求之前的处理
    return config
},
    error => {
        // 请求错误提示
        return Promise.reject(error)
    })
// 配置响应拦截器
http.interceptors.response.use(response => {
    // 响应数据
    return response.data
},
    error => {
        // 响应错误提示
        return Promise.reject(error)
    })

// GET测试
export const testget = (data: any) => {
    return http.get(`${URL}${api.test}`, { params: data })
}

// POST测试
export const testpost = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${URL}${api.test}`, data, option)
}

// ===================用户模块===========================
// 登录接口
export const login = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.login}`, data, option)
}

// 注册接口
export const register = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.regsiter}`, data, option)
}

// 注册接口短信验证码
export const register2 = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.regsiter2}`, data, option)
}
// 发送验证接口
export const sendCode = (data: any) => {
    return http.get(`${HOST_URL}${api.user.sendCode}`, { params: data })
}
// 上传头像的接口
export const upLoadImg = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.uploadImg}`, data, option)
}
// 保存头像的接口
export const saveImg = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.saveImg}`, data, option)
}
// 删除头像的接口
export const deleteImg = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.user.deleteImg}`, data, option)
}
// 获取用户头像和昵称接口
export const getAvatorNickName = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.get(`${HOST_URL}${api.user.getAvatorNickName}`, { params: data })
}
// ===================其他模块===========================

// 获取热门推荐的接口
export const getHotList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.hotList}`, option)
}
// 获取所有数据的接口
export const getAllList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.allList}`, option)
}
export const getTopList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.topList}`, option)
}
export const getDrinkList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.drinkList}`, option)
}
export const getFoodList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.foodList}`, option)
}
export const getGoodsList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.goodsList}`, option)
}
export const getShopList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.shopList}`, option)
}

//获取产品内容的接口
export const getConList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.contentList}`, data, option)
}

// 修改产品总计的价格
export const getTotalList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.totalList}`, data, option)
}

// 增加购物车列表数据
export const getAddList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addList}`, data, option)
}

// 获取购物车列表数据
export const carList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.carList}`, option)
}
// 删除购物车列表数据
export const removeList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.removeList}`, option)
}
// 删除购物车列表数据
export const removeCar = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.removeCar}`, option)
}
// 搜索内容列表数据
export const getSearchList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.searchList}`, data, option)
}
// 添加订单数据
export const getOrderList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addOrder}`, data, option)
}
// 查询订单数据
export const orderList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.orderList}`, option)
}
// 删除订单数据
export const removeOrder = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.removeOrder}`, data, option)
}
// 添加已完成订单数据
export const getFinishList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addFinish}`, data, option)
}
// 查询已完成订单数据
export const finishList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.finishList}`, option)
}
// 添加未完成订单数据
export const getUndoneList = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addUndone}`, data, option)
}
// 查询未完成订单数据
export const undoneList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.undoneList}`, option)
}
// 删除未订单数据
export const removeUndone = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.removeUndone}`, data, option)
}
// 添加地址数据
export const getAddress = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.address}`, data, option)
}
// 查询地址
export const addressList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addressList}`, option)
}
// 添加收藏
export const getCollect = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.addCollect}`, data, option)
}
// 查询收藏
export const collectList = (option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.collectList}`, option)
}
// 删除收藏
export const removeCollect = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.removeCollect}`, data, option)
}
// 修改杯型
export const modifyCup = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.modifyCup}`, data, option)
}

// 修改温度
export const modifyTemp = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.modifyTemp}`, data, option)
}

//修改糖度
export const modifySugar = (data: any, option: any = { headers: 'application/x-www-form-urlencoded' }) => {
    return http.post(`${HOST_URL}${api.hot.modifySugar}`, data, option)
}